package com.vote.www.controller;

import com.vote.www.service.SpokesmanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by 汤伟杰 on 2017/4/18.
 */
@Controller
@RequestMapping("/spokesman")
public class IndexController extends BaseController{
    @Autowired
    private SpokesmanService spokesmanService;
    /**
     * 代言人投票测试
     * @param req
     * @param resp
     * @param model
     */
 /*   @RequestMapping("index.do")*/
    public void index(HttpServletRequest req, HttpServletResponse resp,
                      ModelMap model){

        try {



            jsonResult(1,"00","查询",spokesmanService.getIndex(req),resp);
        } catch (Exception e) {
            e.printStackTrace();
            jsonResult(0,"00","查询出错","",resp);
        }
    }

    /**
     * 爱心代言人（红色出行代言人）
     * @param pageNo
     * @param pageSize
     * @param req
     * @param resp
     * @param model
     */
    @RequestMapping("love.do")
    public void love(String pageNo,
                      String pageSize,
                      HttpServletRequest req, HttpServletResponse resp,
                      ModelMap model){

        try {
            jsonResult(1,"","查询红色出行代言人",spokesmanService.findListMap(1,pageNo,pageSize),resp);
        } catch (Exception e) {
            e.printStackTrace();
            jsonResult(0,"00","查询出错","",resp);
        }
    }

    /**
     * 快乐代言人（橙色出行代言人）
     * @param pageNo
     * @param pageSize
     * @param req
     * @param resp
     * @param model
     */

    @RequestMapping("happy.do")
    public void happy(String pageNo,
                      String pageSize,
                      HttpServletRequest req, HttpServletResponse resp,
                      ModelMap model){

        try {
            jsonResult(1,"","查询橙色出行代言人",spokesmanService.findListMap(3,pageNo,pageSize),resp);
        } catch (Exception e) {
            e.printStackTrace();
            jsonResult(0,"00","查询出错","",resp);
        }
    }

    /**
     * 环保代言人（绿色出行代言人）
     * @param pageNo
     * @param pageSize
     * @param req
     * @param resp
     * @param model
     */
    @RequestMapping("evmp.do")
    public void evmp(String pageNo,
                      String pageSize,
                      HttpServletRequest req, HttpServletResponse resp,
                      ModelMap model){

        try {
            jsonResult(1,"","查询绿色出行代言人",spokesmanService.findListMap(2, pageNo, pageSize),resp);
        } catch (Exception e) {
            e.printStackTrace();
            jsonResult(0,"00","查询出错","",resp);
        }
    }

    /**
     * 获取3个代言人类型的冠军
     * @param req
     * @param resp
     * @param model
     */
    @RequestMapping("result.do")
    public void result(HttpServletRequest req, HttpServletResponse resp,
                     ModelMap model){

        try {
            Object data = spokesmanService.getResult();
            jsonResult(1,"","查询出行代言人公布结果",data,resp);
        } catch (Exception e) {
            e.printStackTrace();
            jsonResult(0,"00","查询出错","",resp);
        }
    }
}
